package com.applink.sell_proof.model;

import java.util.ArrayList;
import java.util.Date;

import com.applink.sell_proof.database.table.ProjectDBHelper;
import com.applink.sell_proof.util.Utility;

public class Project {

	private String id = "";
	private String name = "";
	private String mCustomerCompanyName = "";
	private String mStatus = "";

	private int amount = 0;
	private long date = 0;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		remeberUpdated(ProjectDBHelper.NAME);
		this.name = name;
	}

	public String getCustomerCompanyName() {
		return mCustomerCompanyName;
	}

	public void setCustomerCompanyName(String customer_company_name) {
		remeberUpdated(ProjectDBHelper.CUSTOMER_COMPANY_NAME);
		this.mCustomerCompanyName = customer_company_name;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		remeberUpdated(ProjectDBHelper.AMOUNT);
		this.amount = amount;
	}

	public long getDate() {
		return date;
	}

	public void setDate(long date) {
		remeberUpdated(ProjectDBHelper.DATE);
		this.date = date;
	}

	/**
	 * Special handle for input a date string out put a Unix timestamp long
	 * 
	 * @param s
	 */
	public void setDate(String s) {

		if ((s == null) || s.equals("") || s.equals("null"))
			return;

		try {
			Date d = Utility.findDate(s);
			this.date = d.getTime();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		remeberUpdated(ProjectDBHelper.ID);
		this.id = id;
	}

	public String getStatus() {
		return mStatus;
	}

	public void setStatus(String mStatus) {
		remeberUpdated(ProjectDBHelper.STATUS);
		this.mStatus = mStatus;
	}

	private boolean mIsNewInsert = false;

	public boolean isNewInsert() {
		return mIsNewInsert;
	}

	public void setNewInsert(boolean b) {
		mIsNewInsert = b;
	}

	private ArrayList<String> mUpdatedfilelds = new ArrayList<String>();

	public void remeberUpdated(String field) {
		if (!mUpdatedfilelds.contains(field))
			mUpdatedfilelds.add(field);
	}

	public boolean isUpdated(String field) {
		return mUpdatedfilelds.contains(field);
	}
}
